/**
 * struct TreeNode {
 *	int val;
 *	struct TreeNode *left;
 *	struct TreeNode *right;
 * };
 */

class Solution {
public:
    /**
     * 
     * @param root TreeNode类 
     * @return int整型vector<vector<>>
     */
    /*
    准备一个队列，让根结点指针入队
    出队，访问，如果左子树不空，左子树入队，右不为空，右入队，
    */
    vector<vector<int>> ans;
    vector<vector<int> > levelOrder(TreeNode* root) {
        // write code here
        if(root==nullptr)
            return ans;
        queue<TreeNode*>q;
        q.push(root);
        while(!q.empty())
        {
            int len=q.size();
            vector<int>vec;
            for(int i=0;i<len;i++)
            {
                auto tmp=q.front();
                q.pop();
                vec.push_back(tmp->val);
                if(tmp->left)
                    q.push(tmp->left);
                if(tmp->right)
                    q.push(tmp->right);
            }
            ans.push_back(vec);
        }
        return ans;
    }
};